/*
 * @Author: xuetao 3168581151@qq.com
 * @Date: 2025-02-06
 * @LastEditors: xuetao 3168581151@qq.com
 * @LastEditTime: 2025-04-16
 * @Description: 文件服务
 */
import 'package:chat_client/services/api_service.dart';
import 'package:chat_client/utils/image-picker/image_picker_helper.dart';
import 'package:dio/dio.dart';
import 'package:image_picker/image_picker.dart';

class FileService {
  // 单例模式
  FileService._internal();
  static final FileService _instance = FileService._internal();
  static FileService get instance => _instance;

  final ApiService apiService = ApiService.instance;

  /// 发送文件类型消息
  Future<void> sendFileMessage({
    XFile? file,
  }) async {
    MultipartFile? avatarFile;

    if (file != null) {
      avatarFile = await ImagePickerHelper.convertXFileToMultipart(file);
    }
    final formData = FormData.fromMap({
      if (avatarFile != null) 'avatar': avatarFile,
    });
    final registerResponse =
        await apiService.postFormData('/auth/register', formData);
  }
}
